package com.whx.yimixian.ui.main.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.whx.yimixian.R;
import com.whx.yimixian.adapter.MyMainAdapter;
import com.whx.yimixian.base.BaseActivity;
import com.whx.yimixian.ui.dingdan.activity.DingDanFragment;
import com.whx.yimixian.ui.fenlei.activity.FeiLeiFragment;
import com.whx.yimixian.ui.home.activity.HomeFragment;
import com.whx.yimixian.ui.me.activity.MeFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends BaseActivity {


    @BindView(R.id.main_vp)
    ViewPager mainVp;
    @BindView(R.id.mian_home_rb)
    Button mianHomeRb;
    @BindView(R.id.mian_fenlei_rb)
    Button mianFenleiRb;
    @BindView(R.id.mian_car_iv)
    ImageView mianCarIv;
    @BindView(R.id.mian_dingd_rb)
    Button mianDingdRb;
    @BindView(R.id.mian_me_rb)
    Button mianMeRb;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initData() {
        List<Fragment> list = new ArrayList<>();
        HomeFragment homeFragment = new HomeFragment();
        FeiLeiFragment feileiFragment = new FeiLeiFragment();
        DingDanFragment dingdFragment = new DingDanFragment();
        final MeFragment meFragment = new MeFragment();
        list.add(homeFragment);
        list.add(feileiFragment);
        list.add(dingdFragment);
        list.add(meFragment);
        MyMainAdapter adapter = new MyMainAdapter(getSupportFragmentManager());
        adapter.setData(list);
        mainVp.setAdapter(adapter);
        mainVp.setOffscreenPageLimit(3);
        //设置默认显示
        mainVp.setCurrentItem(0);
        //设置监听同步下方按钮
        mainVp.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                switch (position) {
                    case 0:
                        mianHomeRb.setBackgroundResource(R.mipmap.home_home_icon_p);
                        mianFenleiRb.setBackgroundResource(R.mipmap.ic_home_kind);
                        mianDingdRb.setBackgroundResource(R.mipmap.home_order_icon);
                        mianMeRb.setBackgroundResource(R.mipmap.home_account_icon);
                        break;
                    case 1:
                        mianHomeRb.setBackgroundResource(R.mipmap.home_home_icon);
                        mianFenleiRb.setBackgroundResource(R.mipmap.ic_home_kind_p);
                        mianDingdRb.setBackgroundResource(R.mipmap.home_order_icon);
                        mianMeRb.setBackgroundResource(R.mipmap.home_account_icon);
                        break;
                    case 2:
                        mianHomeRb.setBackgroundResource(R.mipmap.home_home_icon);
                        mianFenleiRb.setBackgroundResource(R.mipmap.ic_home_kind);
                        mianDingdRb.setBackgroundResource(R.mipmap.home_order_icon_p);
                        mianMeRb.setBackgroundResource(R.mipmap.home_account_icon);
                        break;
                    case 3:
                        mianHomeRb.setBackgroundResource(R.mipmap.home_home_icon);
                        mianFenleiRb.setBackgroundResource(R.mipmap.ic_home_kind);
                        mianDingdRb.setBackgroundResource(R.mipmap.home_order_icon);
                        mianMeRb.setBackgroundResource(R.mipmap.home_account_icon_p);
                        break;
                }
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.mian_home_rb, R.id.mian_fenlei_rb, R.id.mian_car_iv, R.id.mian_dingd_rb, R.id.mian_me_rb})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.mian_home_rb:
                mainVp.setCurrentItem(0);
                break;
            case R.id.mian_fenlei_rb:
                mainVp.setCurrentItem(1);
                break;
            case R.id.mian_car_iv:
                break;
            case R.id.mian_dingd_rb:
                mainVp.setCurrentItem(2);
                break;
            case R.id.mian_me_rb:
                mainVp.setCurrentItem(3);
                break;
        }
    }
}
